<template>
  <div style="background: #fff !important;">
    <!-- <div class="m20" style="background: #409eff; color: #fff; padding: 20px 100px;">风电机组运维检测系统</div> -->
    <div class="w1200 m20">
      <div class="bt">设备配置</div>
      <div style="padding: 20px;">
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">风场名称</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.unit_info.plant_name" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">采集器IP</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.basic_config.collector_ip" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">风场编号</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.unit_info.windfarmid" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">采集器SN</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.basic_config.collector_sn" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">设备编号</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.unit_info.equipment_id" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">NTP服务器IP</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.basic_config.ntp_server_ip" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">设备名称</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.unit_info.device_name" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">时间设置</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.basic_config.time_setting" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">风机类型</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.unit_info.fantype" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">MAC地址</div>
            <div><el-input :disabled="chakan == 1" v-model="all.device_config.basic_config.mac_address" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
      </div>
    </div>

    <div class="w1200 m20">
      <div class="bt">modbus配置</div>
      <div style="padding: 20px;">
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">选择设备</div>
            <!-- @change="modbus_tcpchange()" -->
            <div><el-select :disabled="chakan == 1" v-model="modbus_tcps.who" style="width: 100%;" placeholder="请选择">
                <el-option v-for="item in modbus_tcp" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">端口号</div>
            <div><el-input :disabled="chakan == 1" v-model="modbus_tcps.port" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">设备</div>
            <div><el-input :disabled="chakan == 1" v-model="modbus_tcps.id" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
      </div>
    </div>

    <div class="w1200 m20">
      <div class="bt">modbus485配置</div>
      <div style="padding: 20px;">

        <div class="flex m20">
          <div class="w50">
            <div>modbus485_1</div>
            <div class="w50 mb10">
              <div class="mb10">波特率</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_1.baudrate" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">校验位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_1.parity" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">停止位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_1.stopbits" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">数据位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_1.bytesize" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">超时</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_1.timeout" placeholder="请输入内容"></el-input></div>
            </div>
          </div>
          <div class="w50">
            <div>modbus485_2</div>
            <div class="w50 mb10">
              <div class="mb10">波特率</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_2.baudrate" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">校验位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_2.parity" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">停止位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_2.stopbits" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">数据位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_2.bytesize" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">超时</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_2.timeout" placeholder="请输入内容"></el-input></div>
            </div>
          </div>
          <div class="w50">
            <div>modbus485_3</div>
            <div class="w50 mb10">
              <div class="mb10">波特率</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_3.baudrate" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">校验位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_3.parity" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">停止位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_3.stopbits" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">数据位</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_3.bytesize" placeholder="请输入内容"></el-input></div>
            </div>
            <div class="w50 mb10">
              <div class="mb10">超时</div>
              <div><el-input :disabled="chakan == 1" v-model="all.modbus485_config.serial_485_3.timeout" placeholder="请输入内容"></el-input></div>
            </div>
          </div>
        </div>
      </div>


      <div style="padding: 20px;">
        <div class="m20">主站设备</div>

        <el-table :data="all.modbus485_config.devices" border style="width: 100%" class="m20">
          <el-table-column prop="name" label="名称">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.name" placeholder="请输入内容"></el-input></div>
            </template>

          </el-table-column>
          <el-table-column prop="role" label="角色">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.role" placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="modbus_addr" label="地址">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.modbus_addr" placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="function_code" label="功能码">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.function_code" placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="register" label="寄存器">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.register" placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="length" label="长度">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.length" disabled placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="refresh_hz" label=" 刷新频率">
            <template slot-scope="scope">
              <div><el-input :disabled="chakan == 1" v-model="scope.row.refresh_hz" placeholder="请输入内容"></el-input></div>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="操作" width="150px">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.$index)">编辑</el-button>
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-button @click="tianjiazhanzhan">添加主站</el-button>
      </div>
      <el-dialog title="参数修改" :visible.sync="zhuzhanLog" width="1200px">

        <el-table :data="all.modbus485_config.devices[zhuanzhanindex].parameters" border style="width: 100%">
          <el-table-column prop="calibration" label="校准角度">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.calibration" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="datatype" label="数据类型">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.datatype" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="description" label="参数描述">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.description" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="display_name" label="显示名称">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.display_name" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="endianness" label="大端小端模式">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.endianness" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="名称">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.name" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="registers" label="寄存器地址">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.registers" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="scale" label="标定因数">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.scale" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="unit" label="单位">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.unit" disabled placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
        </el-table>

        <span slot="footer" class="dialog-footer">
          <el-button @click="zhuzhanLog = false">关闭</el-button>
        </span>

      </el-dialog>


      <div style="padding: 20px;">
        <div class="m20">从站设备</div>

        <!-- "modbus_addr": 10,
                "name": "本模块对外寄存器",
                "register_map": [
                    {
                        "datatype": "int16",
                        "endianness": "",
                        "name": "采集温度",
                        "register": 0,
                        "scale": 0.1,
                        "unit": "℃"
                    },
                    {
                        "datatype": "float32",
                        "endianness": "big",
                        "name": "采集风速",
                        "register": 2,
                        "scale": 1.0,
                        "unit": "m/s"
                    }
                ],
                "role": "slave" -->

        <el-table :data="devices2" border style="width: 100%" class="m20">
          <el-table-column prop="name" label="名称">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.name" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="role" label="角色">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.role" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="modbus_addr" label="地址">
            <template slot-scope="scope">
              <el-input :disabled="chakan == 1" v-model="scope.row.modbus_addr" placeholder="请输入内容"></el-input>
            </template>
          </el-table-column>

          <el-table-column prop="date" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit2(scope.$index, scope.row)">编辑</el-button>
              <el-button size="mini" type="danger" @click="handleDelete2(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-button @click="tianjiazhanzhan2">添加从站</el-button>
      </div>
    </div>

    <el-dialog title="参数修改" :visible.sync="congzhanlog" width="1200px">
      <el-table :data="devices2[congzhanindex].register_map" border style="width: 100%">
        <el-table-column prop="datatype" label="数据类型">
          <template slot-scope="scope">
            <el-input :disabled="chakan == 1" v-model="scope.row.datatype" placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="endianness" label="大端小端模式">
          <template slot-scope="scope">
            <el-input :disabled="chakan == 1" v-model="scope.row.endianness" placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="名称">
          <template slot-scope="scope">
            <el-input :disabled="chakan == 1" v-model="scope.row.name" placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="scale" label="标定因数">
          <template slot-scope="scope">
            <el-input :disabled="chakan == 1" v-model="scope.row.scale" placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="unit" label="单位">
          <template slot-scope="scope">
            <el-input :disabled="chakan == 1" v-model="scope.row.unit" disabled placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="congzhanlog = false">关闭</el-button>
      </span>
    </el-dialog>


    <!-- 采集策略配置 -->
    <div class="w1200 m20">
      <div class="bt">采集策略配置</div>
      <div style="padding: 20px;">
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">选择策略</div>
            <div><el-select :disabled="chakan == 1" v-model="acquisition_strategiess.who" style="width: 100%;" placeholder="请选择">
                <el-option v-for="item in acquisition_strategies" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">存储间隔</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.raw_data_interval" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">转速采集频率</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.rpm_sampling_frequency" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">采集周期</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.sampling_cycle" placeholder="请输入内容"></el-input>
            </div>
          </div>
          <div class="w50">
            <div class="mb10">采集频率</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.sampling_frequency" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">采集间隔</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.sampling_interval" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">采集点数</div>
            <div><el-input :disabled="chakan == 1" v-model="acquisition_strategiess.sampling_points" placeholder="请输入内容"></el-input>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 解码器配置 -->
    <div class="w1200 m20">
      <div class="bt">解码器配置</div>
      <div style="padding: 20px;">
        <div class="w50">
          <div class="mb10">解码器encoder1</div>
        </div>
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">更新频率</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder1.update_frequency" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">倍数频率</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder1.mode" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">每圈脉冲数</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder1.pulses_per_revolution" placeholder="请输入内容"></el-input>
            </div>
          </div>
        </div>
        <div class="w50">
          <div class="mb10">解码器encoder2</div>
        </div>
        <div class="flex m20">

          <div class="w50">
            <div class="mb10">更新频率</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder2.update_frequency" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">倍数频率</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder2.mode" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">每圈脉冲数</div>
            <div><el-input :disabled="chakan == 1" v-model="all.encoder_config.encoder2.pulses_per_revolution" placeholder="请输入内容"></el-input>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 测点配置 -->
    <div class="w1200 m20">
      <div class="bt">测点配置</div>
      <div style="padding: 20px;">
        <div class="m20">
          <div class="w50">
            <div class="mb10">通道使能</div>
            <div class="flex m20" style="justify-content: flex-start;">
              加速度通道：
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_1.enable">通道1</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_2.enable">通道2</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_3.enable">通道3</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_4.enable">通道4</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_5.enable">通道5</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_6.enable">通道6</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_7.enable">通道7</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_8.enable">通道8</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_9.enable">通道9</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_10.enable">通道10</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_11.enable">通道11</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_12.enable">通道12</el-checkbox>
            </div>

            <div class="flex m20" style="justify-content: flex-start;">
              温度通道：
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_13.enable">通道13</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_14.enable">通道14</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_15.enable">通道15</el-checkbox>
              <el-checkbox :disabled="chakan == 1" v-model="all.measurement_config.measurement_points.point_16.enable">通道16</el-checkbox>
            </div>

            <div class="w50 m20">
              <div class="mb10">选择通道</div>
              <div><el-select :disabled="chakan == 1" v-model="tongdaoji" placeholder="请选择">
                  <el-option v-for="(item,index) in tongdaojis" :key="index" :label="'通道'+(index+1)" :value="index+1">
                  </el-option>
                </el-select>
              </div>
            </div>

            <div class="flex m20">
              <div class="w50">
                <div class="mb10">测点信息</div>
                <div class="w50 mb10">
                  <div class="mb10">测点信息</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.measurement_points['point_'+tongdaoji].position"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">名称</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.measurement_points['point_'+tongdaoji].name"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">ehno</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.measurement_points['point_'+tongdaoji].enable"
                      placeholder="请输入内容"></el-input></div>
                </div>
              </div>
              <div class="w50">
                <div class="mb10">通道信息</div>
                <div class="w50 mb10">
                  <div class="mb10">增益</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].gain"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">偏置</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].offset"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">上限阈值</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].threshold_max"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">下限阈值</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].threshold_min"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">采样率（Hz）</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].sampling_rate"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">采样点数</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.channel_config['channel_'+tongdaoji].sampling_points"
                      placeholder="请输入内容"></el-input></div>
                </div>
              </div>
              <div class="w50">
                <div class="mb10">传感器参数</div>
                <div class="w50 mb10">
                  <div class="mb10">灵敏度</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.sensor_config['sensor_'+tongdaoji].sensitivity"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">型号</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.sensor_config['sensor_'+tongdaoji].model"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50 mb10">
                  <div class="mb10">名称</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.sensor_config['sensor_'+tongdaoji].name"
                      placeholder="请输入内容"></el-input></div>
                </div>
              </div>
            </div>
            <div class="w50">
              <div class="mb10">全局通用（所有通道公用）</div>
              <div class="flex m20">
                <div class="w50">
                  <div class="mb10">数据回传使能</div>
                  <div><el-select :disabled="chakan == 1" v-model="all.measurement_config.general_config.data_return_config.enable"
                      placeholder="请选择">
                      <el-option label="是" :value="true"></el-option>
                      <el-option label="否" :value="false"></el-option>
                    </el-select>
                  </div>
                </div>
                <div class="w50">
                  <div class="mb10">回传间隔（s）</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.general_config.data_return_config.interval"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50">
                  <div class="mb10">采购间隔（s）</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.general_config.feature_interval"
                      placeholder="请输入内容"></el-input></div>
                </div>
                <div class="w50">
                  <div class="mb10">特征间隔（s）</div>
                  <div><el-input :disabled="chakan == 1" v-model="all.measurement_config.general_config.sampling_interval"
                      placeholder="请输入内容"></el-input></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>


    <!-- 阈值配置 -->
    <div class="w1200 m20">
      <div class="bt">阈值配置</div>
      <div style="padding: 20px;">
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">CPU阈值</div>
            <div><el-input :disabled="chakan == 1" v-model="all.threshold_config.device_thresholds.cpu_max_threshold"
                placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">内存阈值</div>
            <div><el-input :disabled="chakan == 1" v-model="all.threshold_config.device_thresholds.ram_max_threshold"
                placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">温度上限</div>
            <div><el-input :disabled="chakan == 1" v-model="all.threshold_config.device_thresholds.temperature_max_threshold"
                placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">温度下限</div>
            <div><el-input :disabled="chakan == 1" v-model="all.threshold_config.device_thresholds.temperature_min_threshold"
                placeholder="请输入内容"></el-input></div>
          </div>
        </div>
      </div>
    </div>

    <!-- SFTP配置 -->
    <div class="w1200 m20">
      <div class="bt">SFTP配置</div>
      <div style="padding: 20px;">
        <div class="flex m20">
          <div class="w50">
            <div class="mb10">服务器IP</div>
            <div><el-input :disabled="chakan == 1" v-model="all.sftp_config.sftp.host" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">用户名</div>
            <div><el-input :disabled="chakan == 1" v-model="all.sftp_config.sftp.username" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">密码</div>
            <div><el-input :disabled="chakan == 1" v-model="all.sftp_config.sftp.password" placeholder="请输入内容"></el-input></div>
          </div>
          <div class="w50">
            <div class="mb10">远程路径</div>
            <div><el-input :disabled="chakan == 1" v-model="all.sftp_config.sftp.remote_path" placeholder="请输入内容"></el-input></div>
          </div>
        </div>
      </div>
    </div>

    <div class="w1200 m20 flexc" style="border: 0; padding-bottom: 50px;">
      <el-upload class="avatar-uploader" v-if="chakan == 2" action="#" :on-change="(file, fileList) => {uploadok(file, fileList)}" :auto-upload="false" :show-file-list="false">
        <el-button type="primary">读取</el-button>
      </el-upload>

      <el-button type="primary" style="margin-left: 20px;" @click="baocun">保存</el-button>
      <el-button type="primary" @click="chongzhi" v-if="chakan == 2">重置</el-button>
    </div>
  </div>
</template>

<script>
  import {
    caijizhanpeizhi
  } from '@/api/caijizhanxin.js'
  export default {
    name: 'chakancanshu',
    data: function() {
      return {
        chakan: 2,
        devices2: [{ //从站信息，使用uart_485_3
            "modbus_addr": "",
            "name": "",
            "register_map": [{
                "datatype": "int16",
                "endianness": "",
                "name": "采集温度",
                "register": 0,
                "scale": 0.1,
                "unit": "℃"
              },
              {
                "datatype": "float32",
                "endianness": "big",
                "name": "采集风速",
                "register": 2,
                "scale": 1.0,
                "unit": "m/s"
              }
            ]
          }

        ],
        congzhanindex: 0,
        congzhanlog: false,

        zhuanzhanall: {
          "datatype": "", //数据类型
          "description": "", //参数描述
          "display_name": "", //显示名称
          "endianness": "", //大端小端模式
          "name": "", //名称
          "registers": [],
          "scale": "", //标定因数
          "unit": "度" //单位
        },
        zhuanzhanindex: 0,
        tongdaoji: 1,
        tongdaojis: ['通道1', '通道2', '通道3', '通道4', '通道5', '通道6', '通道7', '通道8', '通道9', '通道10', '通道11', '通道12',
          '通道13', '通道14', '通道15', '通道16'
        ],
        zhuzhanLog: false,
        modbus_tcps: {
          who: "",
          id: "",
          port: ""
        },
        modbus_tcp: ["bms", "cms", "tms"],
        acquisition_strategies: ["bms", "cms_definition_1", "cms_definition_2", "cms_long_data", "tms"],
        acquisition_strategiess: {
          "who": "",
          "raw_data_interval": "", //存储间隔（s）
          "rpm_sampling_frequency": "", //转速采集频率（Hz）
          "sampling_cycle": "", //采集周期（s）
          "sampling_frequency": "", //采集频率（Hz）
          "sampling_interval": "", //采集间隔（s）
          "sampling_points": "" //采集点数
        },
        encoder_config: ['encoder1', 'encoder2'],
        encoder_configs: {
          who: "",
          "mode": 1, //无效参数，不需要配置
          "pulses_per_revolution": "", //每圈脉冲数
          "update_frequency": "" //更新频率（Hz）
        },
        all: {

          "measurement_config": { //采集参数配置
            "channel_config": { //通道配置
              "channel_1": {},
              "channel_2": {},
              "channel_3": {},
              "channel_4": {},
              "channel_5": {},
              "channel_6": {},
              "channel_7": {},
              "channel_8": {},
              "channel_9": {},
              "channel_10": {},
              "channel_11": {},
              "channel_12": {},
              "channel_13": {},
              "channel_14": {},
              "channel_15": {},
              "channel_16": {},
            },
            "measurement_points": { //测点信息
              "point_1": {},
              "point_2": {},
              "point_3": {},
              "point_4": {},
              "point_5": {},
              "point_6": {},
              "point_7": {},
              "point_8": {},
              "point_9": {},
              "point_10": {},
              "point_11": {},
              "point_12": {},
              "point_13": {},
              "point_14": {},
              "point_15": {},
              "point_16": {},
            },
            "general_config": { //全局参数（所有通道公用），未使用
              "data_return_config": { //数据回传配置
                "enable": true, //数据回传使能
                "interval": "" //回传间隔（s）
              },
              "feature_interval": "", //特征值间隔（s）
              "sampling_interval": "" //采集间隔（s）
            },

            "sensor_config": { //传感器信息
              "sensor_1": {},
              "sensor_2": {},
              "sensor_3": {},
              "sensor_4": {},
              "sensor_5": {},
              "sensor_6": {},
              "sensor_7": {},
              "sensor_8": {},
              "sensor_9": {},
              "sensor_10": {},
              "sensor_11": {},
              "sensor_12": {},
              "sensor_13": {},
              "sensor_14": {},
              "sensor_15": {},
              "sensor_16": {},
            }
          },

          "threshold_config": { //设备报警阈值管理
            "device_thresholds": {
              "cpu_max_threshold": "", //CPU阈值（%）
              "ram_max_threshold": "", //内存阈值（%）
              "temperature_max_threshold": "", //CPU温度上限
              "temperature_min_threshold": "" //CPU温度下限
            },
          },
          "sftp_config": { //sftp参数设置
            "sftp": {
              "host": "", //远端ip
              "password": "", //密码
              "remote_path": "", //路径
              "username": "" //远端名称
            }
          },
          jiasudu: [],
          "encoder_config": { //转速配置
            "encoder1": {

            },
            "encoder2": {

            }
          },
          "acquisition_strategy_config": { //采集策略设置
            "acquisition_strategies": {
              //等保存时候写入
              // "bms": {      //采集策略
              //     "raw_data_interval": 1800,  //存储间隔（s）
              //     "rpm_sampling_frequency": 50,  //转速采集频率（Hz）
              //     "sampling_cycle": 1310.72,  //采集周期（s）
              //     "sampling_frequency": 50,  //采集频率（Hz）
              //     "sampling_interval": 1800,  //采集间隔（s）
              //     "sampling_points": "64k加速度波形"  //采集点数
              // },
            }
          },
          "device_config": { //设备配置信息
            "basic_config": { //基础信息

            },
            "unit_info": { //设备信息

            }
          },
          "modbus_config": { //modbus配置
            "modbus_tcp": {

            }
          },
          "modbus485_config": { //modbus485参数设置
            "devices": [{ //第一个主站
                "function_code": "", //功能码
                "length": 6, //数据长度（字节）
                "master_port": "", //使用的485端口，可选uart_485_1和uart_485_2
                "modbus_addr": "", //地址
                "name": "", //传感器名称
                "parameters": [ //对应传感器寄存器地址内容
                  { //第一个参数
                    "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  },
                  { //第一个参数
                    "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  },
                  { //第一个参数
                    "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  }
                ],
                "refresh_hz": "", //刷新频率
                "register": "", //寄存器地址
                "role": "" //角色
              },


              // 	"role": "slave"
              // }
            ],
            "serial_485_1": { //串口参数

            },
            "serial_485_2": {

            },
            "serial_485_3": {

            }
          },
        }
      }
    },
    created() {
      if (this.$route.query.collectionId) {
        caijizhanpeizhi(this.$route.query.collectionId).then((response) => {
          this.all = response.data
          // this.all = {
          //   "measurement_config": {
          //     "channel_config": {
          //       "channel_1": {
          //         "gain": "3",
          //         "offset": "4",
          //         "threshold_max": "5",
          //         "threshold_min": "6",
          //         "sampling_rate": "7",
          //         "sampling_points": "8"
          //       },
          //       "channel_2": {
          //         "gain": "44",
          //         "offset": "44",
          //         "threshold_max": "44",
          //         "threshold_min": "44",
          //         "sampling_rate": "44",
          //         "sampling_points": "44"
          //       },
          //       "channel_3": {},
          //       "channel_4": {},
          //       "channel_5": {},
          //       "channel_6": {},
          //       "channel_7": {},
          //       "channel_8": {},
          //       "channel_9": {},
          //       "channel_10": {},
          //       "channel_11": {},
          //       "channel_12": {},
          //       "channel_13": {},
          //       "channel_14": {},
          //       "channel_15": {},
          //       "channel_16": {}
          //     },
          //     "measurement_points": {
          //       "point_1": {
          //         "enable": true,
          //         "position": "1",
          //         "name": "2"
          //       },
          //       "point_2": {
          //         "enable": true,
          //         "position": "44",
          //         "name": "44"
          //       },
          //       "point_3": {},
          //       "point_4": {},
          //       "point_5": {},
          //       "point_6": {},
          //       "point_7": {},
          //       "point_8": {},
          //       "point_9": {},
          //       "point_10": {},
          //       "point_11": {},
          //       "point_12": {},
          //       "point_13": {
          //         "enable": true
          //       },
          //       "point_14": {
          //         "enable": true
          //       },
          //       "point_15": {},
          //       "point_16": {}
          //     },
          //     "general_config": {
          //       "data_return_config": {
          //         "enable": true,
          //         "interval": "5"
          //       },
          //       "feature_interval": "5",
          //       "sampling_interval": "5"
          //     },
          //     "sensor_config": {
          //       "sensor_1": {
          //         "sensitivity": "6",
          //         "model": "6",
          //         "name": "6"
          //       },
          //       "sensor_2": {
          //         "sensitivity": "44",
          //         "model": "55",
          //         "name": "66"
          //       },
          //       "sensor_3": {},
          //       "sensor_4": {},
          //       "sensor_5": {},
          //       "sensor_6": {},
          //       "sensor_7": {},
          //       "sensor_8": {},
          //       "sensor_9": {},
          //       "sensor_10": {},
          //       "sensor_11": {},
          //       "sensor_12": {},
          //       "sensor_13": {},
          //       "sensor_14": {},
          //       "sensor_15": {},
          //       "sensor_16": {}
          //     }
          //   },
          //   "threshold_config": {
          //     "device_thresholds": {
          //       "cpu_max_threshold": "55",
          //       "ram_max_threshold": "55",
          //       "temperature_max_threshold": "55",
          //       "temperature_min_threshold": "555"
          //     }
          //   },
          //   "sftp_config": {
          //     "sftp": {
          //       "host": "555",
          //       "password": "555",
          //       "remote_path": "555",
          //       "username": "555"
          //     }
          //   },
          //   "jiasudu": [],
          //   "encoder_config": {
          //     "encoder1": {
          //       "update_frequency": "1",
          //       "mode": "23",
          //       "pulses_per_revolution": "3"
          //     },
          //     "encoder2": {
          //       "update_frequency": "4",
          //       "mode": "5",
          //       "pulses_per_revolution": "6"
          //     }
          //   },
          //   "acquisition_strategy_config": {
          //     "acquisition_strategies": {
          //       "bms": {
          //         "raw_data_interval": "12",
          //         "rpm_sampling_frequency": "2",
          //         "sampling_cycle": "3",
          //         "sampling_frequency": "4",
          //         "sampling_interval": "56",
          //         "sampling_points": "6"
          //       }
          //     }
          //   },
          //   "device_config": {
          //     "basic_config": {
          //       "collector_ip": "2",
          //       "collector_sn": "4",
          //       "ntp_server_ip": "6",
          //       "time_setting": "8",
          //       "mac_address": "0"
          //     },
          //     "unit_info": {
          //       "device_name": "7",
          //       "windfarmid": "3",
          //       "equipment_id": "5",
          //       "fantype": "9"
          //     }
          //   },
          //   "modbus_config": {
          //     "modbus_tcp": {
          //       "bms": {
          //         "device_id": "2",
          //         "port": "1"
          //       }
          //     }
          //   },
          //   "modbus485_config": {
          //     "devices": [{
          //       "function_code": "5",
          //       "length": 6,
          //       "master_port": "",
          //       "modbus_addr": "4",
          //       "name": "2",
          //       "parameters": [{
          //         "datatype": "1",
          //         "description": "2",
          //         "display_name": "3",
          //         "endianness": "4",
          //         "name": "7",
          //         "registers": "9",
          //         "scale": "2",
          //         "unit": "度"
          //       }, {
          //         "datatype": "1",
          //         "description": "2",
          //         "display_name": "3",
          //         "endianness": "5",
          //         "name": "7",
          //         "registers": "1",
          //         "scale": "2",
          //         "unit": "度"
          //       }, {
          //         "datatype": "1",
          //         "description": "2",
          //         "display_name": "3",
          //         "endianness": "6",
          //         "name": "8",
          //         "registers": "1",
          //         "scale": "2",
          //         "unit": "度"
          //       }],
          //       "refresh_hz": "1",
          //       "register": "6",
          //       "role": "3"
          //     }, {
          //       "function_code": "222",
          //       "length": 6,
          //       "master_port": "",
          //       "modbus_addr": "222",
          //       "name": "222",
          //       "parameters": [{
          //         "datatype": "333",
          //         "description": "333",
          //         "display_name": "33",
          //         "endianness": "3",
          //         "name": "22",
          //         "registers": "2",
          //         "scale": "2",
          //         "unit": "度"
          //       }, {
          //         "datatype": "333",
          //         "description": "33",
          //         "display_name": "33",
          //         "endianness": "3",
          //         "name": "222",
          //         "registers": "2",
          //         "scale": "2",
          //         "unit": "度"
          //       }, {
          //         "datatype": "333",
          //         "description": "333",
          //         "display_name": "3",
          //         "endianness": "33",
          //         "name": "2",
          //         "registers": "22",
          //         "scale": "2",
          //         "unit": "度"
          //       }],
          //       "refresh_hz": "222",
          //       "register": "222",
          //       "role": "222"
          //     }, {
          //       "modbus_addr": "44",
          //       "name": "22",
          //       "register_map": [{
          //         "datatype": "int16",
          //         "endianness": "",
          //         "name": "采集温度",
          //         "register": 0,
          //         "scale": 0.1,
          //         "unit": "℃"
          //       }, {
          //         "datatype": "float32",
          //         "endianness": "big",
          //         "name": "采集风速",
          //         "register": 2,
          //         "scale": 1,
          //         "unit": "m/s"
          //       }],
          //       "role": "3"
          //     }, {
          //       "modbus_addr": "666",
          //       "name": "44",
          //       "register_map": [{
          //         "datatype": "int16",
          //         "endianness": "",
          //         "name": "采集温度",
          //         "register": 0,
          //         "scale": 0.1,
          //         "unit": "℃"
          //       }, {
          //         "datatype": "float32",
          //         "endianness": "big",
          //         "name": "采集风速",
          //         "register": 2,
          //         "scale": 1,
          //         "unit": "m/s"
          //       }],
          //       "role": "555"
          //     }],
          //     "serial_485_1": {
          //       "baudrate": "1",
          //       "parity": "7",
          //       "stopbits": "8",
          //       "bytesize": "9",
          //       "timeout": "1"
          //     },
          //     "serial_485_2": {
          //       "baudrate": "1",
          //       "parity": "3",
          //       "stopbits": "6",
          //       "bytesize": "1",
          //       "timeout": "1"
          //     },
          //     "serial_485_3": {
          //       "baudrate": "2",
          //       "parity": "4",
          //       "stopbits": "5",
          //       "bytesize": "1",
          //       "timeout": "1"
          //     }
          //   }
          // }

          if(this.all.modbus_config.modbus_tcp.bms){
            this.modbus_tcps.who = 'bms'
            this.modbus_tcps.id = 2
            this.modbus_tcps.port = 503
          }
          if(this.all.modbus_config.modbus_tcp.cms){
            this.modbus_tcps.who = 'bms'
            this.modbus_tcps.id = 1
            this.modbus_tcps.port = 502
          }
          if(this.all.modbus_config.modbus_tcp.tms){
            this.modbus_tcps.who = 'tms'
            this.modbus_tcps.id = 3
            this.modbus_tcps.port = 504
          }
          if(this.modbus_tcps.who == ''){
            this.all.modbus_config.modbus_tcp.bms = {

            }
          }

          // this.devices2 = []

         // 执行分类
         const [arr1, arr2] = this.all.modbus485_config.devices.reduce((acc, item) => {
           acc[item.length ? 0 : 1].push(item);
           return acc;
         }, [[], []]);

         this.all.modbus485_config.devices = arr1;  // 有 length 的设备
         this.devices2 = arr2;  // 没有 length 的设备

          // this.all.modbus485_config.devices.forEach((item,index)=>{

          //   if(item.length){

          //   }else{
          //      this.devices2.push(item)
          //      this.all.modbus485_config.devices.splice(index, 1);
          //   }
          // })





          if(this.all.acquisition_strategy_config.acquisition_strategies.bms){
            this.acquisition_strategiess = {
              "who": "bms",
              "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.bms.raw_data_interval, //存储间隔（s）
              "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.bms.rpm_sampling_frequency, //转速采集频率（Hz）
              "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_cycle, //采集周期（s）
              "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_frequency, //采集频率（Hz）
              "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_interval, //采集间隔（s）
              "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_points //采集点数
            }
          }

          if(this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1){
            this.acquisition_strategiess = {
              "who": "cms_definition_1",
              "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.raw_data_interval, //存储间隔（s）
              "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.rpm_sampling_frequency, //转速采集频率（Hz）
              "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_cycle, //采集周期（s）
              "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_frequency, //采集频率（Hz）
              "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_interval, //采集间隔（s）
              "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_points //采集点数
            }
          }

          if(this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2){
            this.acquisition_strategiess = {
              "who": "cms_definition_2",
              "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.raw_data_interval, //存储间隔（s）
              "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.rpm_sampling_frequency, //转速采集频率（Hz）
              "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_cycle, //采集周期（s）
              "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_frequency, //采集频率（Hz）
              "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_interval, //采集间隔（s）
              "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_points //采集点数
            }
          }

          if(this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data){
            this.acquisition_strategiess = {
              "who": "cms_long_data",
              "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.raw_data_interval, //存储间隔（s）
              "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.rpm_sampling_frequency, //转速采集频率（Hz）
              "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_cycle, //采集周期（s）
              "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_frequency, //采集频率（Hz）
              "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_interval, //采集间隔（s）
              "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_points //采集点数
            }
          }

          if(this.all.acquisition_strategy_config.acquisition_strategies.tms){
            this.acquisition_strategiess = {
              "who": "tms",
              "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.tms.raw_data_interval, //存储间隔（s）
              "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.tms.rpm_sampling_frequency, //转速采集频率（Hz）
              "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_cycle, //采集周期（s）
              "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_frequency, //采集频率（Hz）
              "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_interval, //采集间隔（s）
              "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_points //采集点数
            }
          }



        })
      }
    },
    mounted() {
      if(this.$route.query.chakan){
        this.chakan = this.$route.query.chakan
      }


    },
    methods: {
      uploadok: function(file, fileList) {


        const reader = new FileReader();
        reader.onload = (e) => {

            this.all = JSON.parse(e.target.result)



            if(this.all.modbus_config.modbus_tcp.bms){
               this.modbus_tcps.who = 'bms'
               this.modbus_tcps.id = 2
               this.modbus_tcps.port = 503
             }
             if(this.all.modbus_config.modbus_tcp.cms){
               this.modbus_tcps.who = 'bms'
               this.modbus_tcps.id = 1
               this.modbus_tcps.port = 502
             }
             if(this.all.modbus_config.modbus_tcp.tms){
               this.modbus_tcps.who = 'tms'
               this.modbus_tcps.id = 3
               this.modbus_tcps.port = 504
             }

             // this.devices2 = []

            // 执行分类
            const [arr1, arr2] = this.all.modbus485_config.devices.reduce((acc, item) => {
              acc[item.length ? 0 : 1].push(item);
              return acc;
            }, [[], []]);

            this.all.modbus485_config.devices = arr1;  // 有 length 的设备
            this.devices2 = arr2;  // 没有 length 的设备

             // this.all.modbus485_config.devices.forEach((item,index)=>{

             //   if(item.length){

             //   }else{
             //      this.devices2.push(item)
             //      this.all.modbus485_config.devices.splice(index, 1);
             //   }
             // })





             if(this.all.acquisition_strategy_config.acquisition_strategies.bms){
               this.acquisition_strategiess = {
                 "who": "bms",
                 "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.bms.raw_data_interval, //存储间隔（s）
                 "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.bms.rpm_sampling_frequency, //转速采集频率（Hz）
                 "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_cycle, //采集周期（s）
                 "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_frequency, //采集频率（Hz）
                 "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_interval, //采集间隔（s）
                 "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.bms.sampling_points //采集点数
               }
             }

             if(this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1){
               this.acquisition_strategiess = {
                 "who": "cms_definition_1",
                 "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.raw_data_interval, //存储间隔（s）
                 "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.rpm_sampling_frequency, //转速采集频率（Hz）
                 "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_cycle, //采集周期（s）
                 "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_frequency, //采集频率（Hz）
                 "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_interval, //采集间隔（s）
                 "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_1.sampling_points //采集点数
               }
             }

             if(this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2){
               this.acquisition_strategiess = {
                 "who": "cms_definition_2",
                 "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.raw_data_interval, //存储间隔（s）
                 "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.rpm_sampling_frequency, //转速采集频率（Hz）
                 "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_cycle, //采集周期（s）
                 "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_frequency, //采集频率（Hz）
                 "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_interval, //采集间隔（s）
                 "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_definition_2.sampling_points //采集点数
               }
             }

             if(this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data){
               this.acquisition_strategiess = {
                 "who": "cms_long_data",
                 "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.raw_data_interval, //存储间隔（s）
                 "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.rpm_sampling_frequency, //转速采集频率（Hz）
                 "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_cycle, //采集周期（s）
                 "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_frequency, //采集频率（Hz）
                 "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_interval, //采集间隔（s）
                 "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.cms_long_data.sampling_points //采集点数
               }
             }

             if(this.all.acquisition_strategy_config.acquisition_strategies.tms){
               this.acquisition_strategiess = {
                 "who": "tms",
                 "raw_data_interval": this.all.acquisition_strategy_config.acquisition_strategies.tms.raw_data_interval, //存储间隔（s）
                 "rpm_sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.tms.rpm_sampling_frequency, //转速采集频率（Hz）
                 "sampling_cycle": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_cycle, //采集周期（s）
                 "sampling_frequency": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_frequency, //采集频率（Hz）
                 "sampling_interval": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_interval, //采集间隔（s）
                 "sampling_points": this.all.acquisition_strategy_config.acquisition_strategies.tms.sampling_points //采集点数
               }
             }
        };
        reader.readAsText(file.raw);

      },
      chongzhi:function(){
        this.devices2 = [{ //从站信息，使用uart_485_3
            "modbus_addr": "",
            "name": "",
            "register_map": [{
                "datatype": "int16",
                "endianness": "",
                "name": "采集温度",
                "register": 0,
                "scale": 0.1,
                "unit": "℃"
              },
              {
                "datatype": "float32",
                "endianness": "big",
                "name": "采集风速",
                "register": 2,
                "scale": 1.0,
                "unit": "m/s"
              }
            ]
          }

        ]
        this.congzhanindex = 0


        this.zhuanzhanall = {
          "datatype": "", //数据类型
          "description": "", //参数描述
          "display_name": "", //显示名称
          "endianness": "", //大端小端模式
          "name": "", //名称
          "registers": [],
          "scale": "", //标定因数
          "unit": "度" //单位
        }
        this.zhuanzhanindex = 0
        this.tongdaoji = 1


        this.modbus_tcps = {
          who: "",
          id: "",
          port: ""
        }


        this.acquisition_strategiess = {
          "who": "",
          "raw_data_interval": "", //存储间隔（s）
          "rpm_sampling_frequency": "", //转速采集频率（Hz）
          "sampling_cycle": "", //采集周期（s）
          "sampling_frequency": "", //采集频率（Hz）
          "sampling_interval": "", //采集间隔（s）
          "sampling_points": "" //采集点数
        }

        this.encoder_configs = {
          who: "",
          "mode": 1, //无效参数，不需要配置
          "pulses_per_revolution": "", //每圈脉冲数
          "update_frequency": "" //更新频率（Hz）
        }
        this.all = {

          "measurement_config": { //采集参数配置
            "channel_config": { //通道配置
              "channel_1": {},
              "channel_2": {},
              "channel_3": {},
              "channel_4": {},
              "channel_5": {},
              "channel_6": {},
              "channel_7": {},
              "channel_8": {},
              "channel_9": {},
              "channel_10": {},
              "channel_11": {},
              "channel_12": {},
              "channel_13": {},
              "channel_14": {},
              "channel_15": {},
              "channel_16": {},
            },
            "measurement_points": { //测点信息
              "point_1": {},
              "point_2": {},
              "point_3": {},
              "point_4": {},
              "point_5": {},
              "point_6": {},
              "point_7": {},
              "point_8": {},
              "point_9": {},
              "point_10": {},
              "point_11": {},
              "point_12": {},
              "point_13": {},
              "point_14": {},
              "point_15": {},
              "point_16": {},
            },
            "general_config": { //全局参数（所有通道公用），未使用
              "data_return_config": { //数据回传配置
                "enable": true, //数据回传使能
                "interval": "" //回传间隔（s）
              },
              "feature_interval": "", //特征值间隔（s）
              "sampling_interval": "" //采集间隔（s）
            },

            "sensor_config": { //传感器信息
              "sensor_1": {},
              "sensor_2": {},
              "sensor_3": {},
              "sensor_4": {},
              "sensor_5": {},
              "sensor_6": {},
              "sensor_7": {},
              "sensor_8": {},
              "sensor_9": {},
              "sensor_10": {},
              "sensor_11": {},
              "sensor_12": {},
              "sensor_13": {},
              "sensor_14": {},
              "sensor_15": {},
              "sensor_16": {},
            }
          },

          "threshold_config": { //设备报警阈值管理
            "device_thresholds": {
              "cpu_max_threshold": "", //CPU阈值（%）
              "ram_max_threshold": "", //内存阈值（%）
              "temperature_max_threshold": "", //CPU温度上限
              "temperature_min_threshold": "" //CPU温度下限
            },
          },
          "sftp_config": { //sftp参数设置
            "sftp": {
              "host": "", //远端ip
              "password": "", //密码
              "remote_path": "", //路径
              "username": "" //远端名称
            }
          },
          jiasudu: [],
          "encoder_config": { //转速配置
            "encoder1": {

            },
            "encoder2": {

            }
          },
          "acquisition_strategy_config": { //采集策略设置
            "acquisition_strategies": {
              //等保存时候写入
              // "bms": {      //采集策略
              //     "raw_data_interval": 1800,  //存储间隔（s）
              //     "rpm_sampling_frequency": 50,  //转速采集频率（Hz）
              //     "sampling_cycle": 1310.72,  //采集周期（s）
              //     "sampling_frequency": 50,  //采集频率（Hz）
              //     "sampling_interval": 1800,  //采集间隔（s）
              //     "sampling_points": "64k加速度波形"  //采集点数
              // },
            }
          },
          "device_config": { //设备配置信息
            "basic_config": { //基础信息

            },
            "unit_info": { //设备信息

            }
          },
          "modbus_config": { //modbus配置
            "modbus_tcp": {

            }
          },
          "modbus485_config": { //modbus485参数设置
            "devices": [{ //第一个主站
                "function_code": "", //功能码
                "length": 6, //数据长度（字节）
                "master_port": "", //使用的485端口，可选uart_485_1和uart_485_2
                "modbus_addr": "", //地址
                "name": "", //传感器名称
                "parameters": [ //对应传感器寄存器地址内容
                  { //第一个参数
                  "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  },
                  { //第一个参数
                  "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  },
                  { //第一个参数
                  "calibration":"",
                    "datatype": "", //数据类型
                    "description": "", //参数描述
                    "display_name": "", //显示名称
                    "endianness": "", //大端小端模式
                    "name": "", //名称
                    "registers": [],
                    "scale": "", //标定因数
                    "unit": "度" //单位
                  }
                ],
                "refresh_hz": "", //刷新频率
                "register": "", //寄存器地址
                "role": "" //角色
              },


              // 	"role": "slave"
              // }
            ],
            "serial_485_1": { //串口参数

            },
            "serial_485_2": {

            },
            "serial_485_3": {

            }
          },
        }
      },
      zhuzhanLoggo: function() {

      },

      handleEdit2: function(index) {
        this.congzhanindex = index
        this.congzhanlog = true
      },
      handleDelete2: function(index) {
        this.devices2.splice(index, 1);
      },
      tianjiazhanzhan2: function() {
        this.devices2.push({ //从站信息，使用uart_485_3
          "modbus_addr": "",
          "name": "",
          "register_map": [{
              "datatype": "int16",
              "endianness": "",
              "name": "采集温度",
              "register": 0,
              "scale": 0.1,
              "unit": "℃"
            },
            {
              "datatype": "float32",
              "endianness": "big",
              "name": "采集风速",
              "register": 2,
              "scale": 1.0,
              "unit": "m/s"
            }
          ]
        })
      },
      handleEdit: function(index) {
        this.zhuanzhanindex = index
        this.zhuzhanLog = true
      },
      handleDelete: function(index) {
        this.all.modbus485_config.devices.splice(index, 1);
      },
      tianjiazhanzhan: function() {
        this.all.modbus485_config.devices.push({ //第一个主站
          "function_code": "", //功能码
          "length": 6, //数据长度（字节）
          "master_port": "", //使用的485端口，可选uart_485_1和uart_485_2
          "modbus_addr": "", //地址
          "name": "", //传感器名称
          "parameters": [ //对应传感器寄存器地址内容
            { //第一个参数
            "calibration":"",
              "datatype": "", //数据类型
              "description": "", //参数描述
              "display_name": "", //显示名称
              "endianness": "", //大端小端模式
              "name": "", //名称
              "registers": [],
              "scale": "", //标定因数
              "unit": "度" //单位
            },
            { //第一个参数
            "calibration":"",
              "datatype": "", //数据类型
              "description": "", //参数描述
              "display_name": "", //显示名称
              "endianness": "", //大端小端模式
              "name": "", //名称
              "registers": [],
              "scale": "", //标定因数
              "unit": "度" //单位
            },
            { //第一个参数
            "calibration":"",
              "datatype": "", //数据类型
              "description": "", //参数描述
              "display_name": "", //显示名称
              "endianness": "", //大端小端模式
              "name": "", //名称
              "registers": [],
              "scale": "", //标定因数
              "unit": "度" //单位
            }
          ],
          "refresh_hz": "", //刷新频率
          "register": "", //寄存器地址
          "role": "" //角色
        })
      },
      baocun: function() {

        this.all.modbus_config.modbus_tcp = {}

        this.all.modbus_config.modbus_tcp[this.modbus_tcps.who] = {
          "device_id": this.modbus_tcps.id,
          "port": this.modbus_tcps.port
        }

        this.all.acquisition_strategy_config.acquisition_strategies[this.acquisition_strategiess.who] = {
          "raw_data_interval": this.acquisition_strategiess.raw_data_interval, //存储间隔（s）
          "rpm_sampling_frequency": this.acquisition_strategiess.rpm_sampling_frequency, //转速采集频率（Hz）
          "sampling_cycle": this.acquisition_strategiess.sampling_cycle, //采集周期（s）
          "sampling_frequency": this.acquisition_strategiess.sampling_frequency, //采集频率（Hz）
          "sampling_interval": this.acquisition_strategiess.sampling_interval, //采集间隔（s）
          "sampling_points": this.acquisition_strategiess.sampling_points //采集点数
        }

        let obj = JSON.parse(JSON.stringify(this.all))

        obj.modbus485_config.devices = [...obj.modbus485_config.devices, ...this.devices2]

        // 创建包含字符串'a'的文本文件
        const content = JSON.stringify(obj);
        const blob = new Blob([content], {
          type: 'text/plain'
        });
        const url = URL.createObjectURL(blob);

        // 创建下载链接并触发下载
        const a = document.createElement('a');
        a.href = url;
        a.download = 'text-file.txt';
        document.body.appendChild(a);
        a.click();

        // 清理
        document.body.removeChild(a);
        URL.revokeObjectURL(url);

        // 显示成功消息
        this.message = '文件下载成功！';
        setTimeout(() => {
          this.message = '';
        }, 3000);

      },

      modbus_tcpchange: function() {
        if (this.modbus_tcps.who == 'bms') {
          this.modbus_tcps.who = 'bms'
          this.modbus_tcps.id = 2
          this.modbus_tcps.port = 503
          this.all.modbus_config.modbus_tcp = {
            "bms": { //bms模式
              "device_id": 2,
              "port": 503
            },
          }
        }
        if (this.modbus_tcps.who == 'cms') {
          this.modbus_tcps.who = 'cms'
          this.modbus_tcps.id = 1
          this.modbus_tcps.port = 502
          this.all.modbus_config.modbus_tcp = {
            "cms": { //cms模式
              "device_id": 1,
              "port": 502
            },
          }
        }
        if (this.modbus_tcps.who == 'tms') {
          this.modbus_tcps.who = 'tms'
          this.modbus_tcps.id = 3
          this.modbus_tcps.port = 504
          this.all.modbus_config.modbus_tcp = {
            "tms": { //tms模式
              "device_id": 3,
              "port": 504
            }
          }
        }
      }

    }
  };
</script>


<style scoped>
  .w1200 {
    width: 1200px;
    margin: 0 auto;
    border: 1px #eee solid;
    border-radius: 10px;
    overflow: hidden;
  }

  .bt {
    background: #eaeaea;
    padding: 10px 20px;
  }

  .flex {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
  }

  .mb10 {
    margin-bottom: 10px;
  }

  .m20 {
    margin-bottom: 20px;
  }

  .w50 {
    flex: 1;
  }
</style>
